<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>动态组件V-once</title>
    <script src="vue.js"></script>
</head>
<body>
<div id="app">
    <component :is="type"></component>
    <!--<child-one v-if="type === 'childone'"></child-one>-->
    <!--<child-two v-if="type === 'childtwo'"></child-two>-->
    <button @click="handleClick">Change</button>
</div>
<script>
    var childOne = {
        template:`<div>
                    this is child-one
                  </div>`
    };
    var childTwo = {
        template:`<div>
                    this is child-two
                  </div>`
    };
    var vm = new Vue({
        el:"#app",
        components:{
            childOne:childOne,
            childTwo:childTwo
        },
        data:{
            type:"childone"
        },
        methods:{
            handleClick:function () {
                this.type = this.type === 'childone' ? 'childtwo' :'childone'
            }
        }
    });
</script>
</body>
</html>